package com.zhaofujun.filequeue;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 周期性删除分段文件的策略
 */
public class PeriodDeleteSegmentStrategy extends DeleteSegmentStrategy {
    private final int period;
    private final TimeUnit timeUnit;

    public PeriodDeleteSegmentStrategy(int period, TimeUnit timeUnit) {
        this.period = period;
        this.timeUnit = timeUnit;
    }

    private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

    @Override
    public void start() {
        scheduler.scheduleAtFixedRate(this::execute, 0, period, timeUnit);
    }

    @Override
    public void stop() {
        scheduler.shutdown();
    }


}
